// $Id: array_access.hpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#ifndef XPCOM_DETAIL_ARRAY_ACCESS_HPP
#define XPCOM_DETAIL_ARRAY_ACCESS_HPP

#include <xpcom/config.hpp>
#include <xpcom/array_fwd.hpp>

#ifdef BOOST_HAS_ABI_HEADERS
#include BOOST_ABI_PREFIX
#endif

namespace xpcom {
namespace detail {

//
// Helper class for access array data.
//
template <typename Array>
struct array_access
{
    typedef Array array_type;
    typedef typename array_type::impl_type impl_type;

    XPCOM_FORCEINLINE
    static const impl_type& impl(const Array& a)
    {
        return a.impl_;
    }

    XPCOM_FORCEINLINE
    static impl_type& impl(Array& a)
    {
        return a.impl_;
    }
};

template <typename T, typename Traits>
XPCOM_FORCEINLINE const typename array_access<array<T, Traits> >::impl_type&
array_access_impl(const array<T, Traits>& a)
{
    return array_access<array<T, Traits> >::impl(a);
}

template <typename T, typename Traits>
XPCOM_FORCEINLINE typename array_access<array<T, Traits> >::impl_type&
array_access_impl(array<T, Traits>& a)
{
    return array_access<array<T, Traits> >::impl(a);
}

template <typename T, typename Traits>
XPCOM_FORCEINLINE const typename array_access<ptr_array<T, Traits> >::impl_type&
array_access_impl(const ptr_array<T, Traits>& a)
{
    return array_access<ptr_array<T, Traits> >::impl(a);
}

template <typename T, typename Traits>
XPCOM_FORCEINLINE typename array_access<ptr_array<T, Traits> >::impl_type&
array_access_impl(ptr_array<T, Traits>& a)
{
    return array_access<ptr_array<T, Traits> >::impl(a);
}

} // namespace xpcom::detail
} // namespace xpcom

#ifdef BOOST_HAS_ABI_HEADERS
#include BOOST_ABI_SUFFIX
#endif

#endif // XPCOM_DETAIL_ARRAY_ACCESS_HPP
